package de.tudarmstadt.ukp.muip.fibqdojo;

import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQBlankSetter;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQRule;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQSentence;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQSentenceToken;
import de.tudarmstadt.ukp.muip.fibqdojo.visitor.GetSentenceTokenListVisitor;

/**
 * Sets a token in a sentence blank according to the provided rule. The
 * <b>first</b> sentence token that applies to the provided rule will be set
 * to blank and the processing ends.
 */
public class BlankSetter implements IFIBQBlankSetter {

    private final IFIBQRule rule;

    public BlankSetter(IFIBQRule rule) {
        this.rule = rule;
    }

    @Override
    public IFIBQSentence setBlankTokens(IFIBQSentence sentence) {

        GetSentenceTokenListVisitor getSentTokens = new GetSentenceTokenListVisitor();
        sentence.accept(getSentTokens);
        for (IFIBQSentenceToken sentenceToken : getSentTokens.getSentenceTokens()) {
            if (rule.match(sentenceToken)) {
                sentenceToken.setBlank(true);
                sentence.setMarked(true);
                break;
            }
        }

        return sentence;
    }

}
